<?php 
	session_start();
	$uname=$_SESSION['uname'];;
	header("Content-Type: text/html; charset=gb2321");

	require_once (dirname(__FILE__).'/includes/dbconn.php');
	require_once (dirname(__FILE__).'/includes/tpl_config.php');
		
	if ($_POST[change]){
		$sql="select * from users where uname='$uname'";
//		
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);	

		$tpl->assign('uid',$row['uid']);			
		$tpl->assign('uname',$uname);
		$tpl->assign('uemail',$row['mail']);
		$tpl->assign('usecq',$row['secque']);
		$tpl->assign('useca',$row['secans']);
		$tpl->assign('name',$row['name']);
		$tpl->assign('sex',$row['sex']);
		$tpl->assign('bday',$row['bday']);
		$tpl->assign('phone',$row['phone']);
		$tpl->assign('short',$row['short']);
		$tpl->assign('qq',$row['qq']);
		$tpl->assign('college',$row['college']);
		$tpl->assign('grade',$row['grade']);
		$tpl->assign('dorm',$row['dorm']);
		$tpl->assign('dept',$row['dept']);
	
		$tpl->display('per_verify.tpl');
	}
	if ($_POST[submit]){
		$uid = $_SESSION['uid'];
//		$uname=$_POST['uname'];
		$secque=$_POST['usecq'];
		$secans=$_POST['useca']; 
		$mail=$_POST['uemail'];
		$name=$_POST['name'];
		$sex=$_POST['sex'];
		$bday=$_POST['bday'];
		$college=$_POST['college'];
		$grade=$_POST['grade'];
		$dorm=$_POST['dorm'];
		$dept=$_POST['dept'];
		$phone=$_POST['phone'];
		$short=$_POST['short'];
		$qq=$_POST['qq'];
		
		$query= "UPDATE users 
				SET secque='$secque',secans='$secans',mail='$mail',name='$name', bday='$bday',college='$college',
				grade='$grade',dorm='$dorm',dept='$dept',phone='$phone',short='$short',qq='$qq'
				WHERE uid='$uid'";
//		echo $query;
//		$query="select * from users where uid=71";
		
		$result=$db->sql_query($query);
//		echo $uname;
		if ($result){
        	echo "<script>alert('"."修改成功"."');location.href='personal.php'</script>";
		}else{
			echo "<script>alert('"."修改失败"."');</script>";
		}
	}
	if($_POST[chacode]){
	   $tpl->assign('uname',$uname);
		$tpl->display('chacode.tpl');
	}
	if($_POST[subcode]){
		$upwd=md5($_POST['upwd']);
	
		$query= "UPDATE users SET upwd='$upwd' where uname='$uname'";
		$result=$db->sql_query($query);
		if ($result){
        	echo "<script>alert('"."修改成功"."');location.href='personal.php'</script>";
		}else{
			echo "<script>alert('"."修改失败"."');</script>";
		}
	}
?>